package logic

import (
	"context"

	"go-zero-all-demos/apps/order/pb/order"
	"go-zero-all-demos/apps/order/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetOrderByIDLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetOrderByIDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderByIDLogic {
	return &GetOrderByIDLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetOrderByID 订单详情
func (l *GetOrderByIDLogic) GetOrderByID(in *order.OrderID) (*order.OrderInfo, error) {
	o, err := l.svcCtx.OrderModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}
	return &order.OrderInfo{Id: o.Id, UserId: o.UserId, OrderId: o.OrderId}, nil
}
